(ns pe.triangles)

(defn num-seq [f]
  (map last (iterate f [1 1])))

(defn num-step [f]
  #(let [n (inc (first %)) next (f n)]
    [n next]))

(defn triangle [n]
  (int (* 0.5 n (inc n))))

(defn tr-seq [] (num-seq (num-step triangle)))

(defn pentag [n]
  (int (* 0.5 n (dec (* 3 n)))))

(defn pent-seq [] (num-seq (num-step pentag)))

(defn hex [n]
  (int (* n (dec (* 2 n)))))

(defn hex-seq [] (num-seq (num-step hex)))